import { defHttp } from "/@/utils/http/axios"
import { Modal } from "ant-design-vue"

enum Api {
  list = "/infra-service/job/log/page",
  delete = "/infra-service/job/log/delete",
  clean = "/infra-service/job/log/clean",
  exportXlsUrl = "/infra-service/job/log/exportXls",
  importExcelUrl = "/infra-service/job/log/importExcel",
  deleteBatch = "/infra-service/job/log/deleteBatch",
}

/**
 * 导出api
 */
export const getExportUrl = Api.exportXlsUrl
/**
 * 导入api
 */
export const getImportUrl = Api.importExcelUrl
/**
 * 查询任务列表
 * @param params
 */
export const getQuartzList = (params) => {
  return defHttp.get({ url: Api.list, params })
}

/**
 * 删除任务
 * @param params
 */
export const cleanJobLog = (handleSuccess) => {
  return defHttp.delete({ url: Api.clean }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

/**
 * 删除任务
 * @param params
 */
export const deleteQuartz = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.delete, data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

/**
 * 批量删除任务
 * @param params
 */
export const batchDeleteQuartz = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}
